//
//  RBBasketBallGameController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/12.
//

#import "RBBasketBallGameController.h"
#import "RBCompeCalendarView.h"
#import "RBCompeCalendarModel.h"
#import "RBCompeRecomViewCell.h"
#import "RBCompeRecommendModel.h"
#import "RBCompeSectionTitleView.h"
#import "RBBasBallGameViewCell.h"
#import "RBCompeRemindModel.h"
#import "RBCompeDetailListController.h"

@interface RBBasketBallGameController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic)NSMutableArray *weekArray;
@property(strong,nonatomic)RBCompeCalendarView *compeCalendarView;
@property(strong,nonatomic)BRStringPickerView *stringPickerView;
@property(strong,nonatomic)NSMutableArray *hotRecomArray;
@property(assign,nonatomic)NSInteger pageNum;
@property(strong,nonatomic)UITableView *tableView;
@property(strong,nonatomic)NSMutableArray *dataArray;
@property(strong,nonatomic)NSMutableArray *collTimeArray;
@property(copy,nonatomic)NSString *searchValue;
@property (nonatomic,assign) NSInteger selectTag;
@end

@implementation RBBasketBallGameController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadNewQueryMatchRowsData) name:@"collectGameSuccess" object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=RBColor(245, 245, 245);
    self.searchValue = @"";
    self.selectTag=0;
    [self rb_initCompCalendarViewUI];
    [self rb_initDateTimeData];
    [self rb_initTableView];
    [self loadQueryRecommendMatchRowsData];
}
-(void)rb_initDateTimeData{
    [self.weekArray removeAllObjects];
    
    self.selectDateTime = [NSDate rb_currentDateStringWithFormat:@"yyyy-MM-dd"];
    NSDate *currentDate = [NSString rb_NSStringChangeDateFormat:@"yyyy-MM-dd" datestring:self.selectDateTime];
    [self rb_competionSocDayModelWithCurrentDate:currentDate day:1 isAddDay:NO isSelectDate:NO];
    [self rb_competionSocDayModelWithCurrentDate:currentDate day:0 isAddDay:YES isSelectDate:YES];
    [self rb_competionSocDayModelWithCurrentDate:currentDate day:1 isAddDay:YES isSelectDate:NO];
    [self rb_competionSocDayModelWithCurrentDate:currentDate day:2 isAddDay:YES isSelectDate:NO];
    [self rb_competionSocDayModelWithCurrentDate:currentDate day:3 isAddDay:YES isSelectDate:NO];
}
- (void)rb_competionSocDayModelWithCurrentDate:(NSDate *)currentDate day:(NSInteger)day isAddDay:(BOOL)isAddDay isSelectDate:(BOOL)isSelectDate{
    NSDate *dayDate;
    if (isAddDay) {
        dayDate = [currentDate dateByAddingDays:day];
    } else {
        dayDate = [currentDate dateBySubtractingDays:day];
    }
    NSString *weekTime = [NSDate rb_dayFromFormatWeekday:dayDate];
    if([dayDate isToday]){
        weekTime = @"今天";
    }
    NSString *dayTime = [dayDate rb_stringWithFormat:@"yyyy-MM-dd"];
    RBCompeCalendarModel *compeCalendarModel = [[RBCompeCalendarModel alloc] init];
    compeCalendarModel.dateTime = dayTime;
    compeCalendarModel.weekTime = weekTime;
    compeCalendarModel.isSelectDate = isSelectDate;
    [self.weekArray addObject:compeCalendarModel];
    self.compeCalendarView.weekArray = self.weekArray;
}
-(void)rb_initCompCalendarViewUI{
    RBCompeCalendarView *compeCalendarView = [[RBCompeCalendarView alloc] init];
    MJWeakSelf
    compeCalendarView.didSelectItemAtIndexPathBlock = ^(RBCompeCalendarModel * _Nonnull compeCalendarModel) {
        weakSelf.selectDateTime = compeCalendarModel.dateTime;
        [weakSelf.tableView.mj_header beginRefreshing];
    };
    self.compeCalendarView = compeCalendarView;
    [self.view addSubview:compeCalendarView];
    [compeCalendarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(RBScaleWidth(44));
    }];
}
-(void)rb_initTableView{
    [self.view addSubview:self.tableView];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.compeCalendarView.mas_bottom);
        make.left.right.bottom.mas_equalTo(0);
    }];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.aimView = self.tableView;
    self.emptyDataImageName = @"qsy_zwxl";
    self.emptyDataText = @"暂无数据";
    self.aimView.mj_footer.hidden = YES;
    [self.tableView.mj_header beginRefreshing];
    
    MJRefreshAutoNormalFooter *normalFooter = (MJRefreshAutoNormalFooter *)self.aimView.mj_footer;
    [normalFooter setTitle:@"已经到底啦～" forState:(MJRefreshStateNoMoreData)];
    normalFooter.stateLabel.font = RBPingFangFont(12);
    normalFooter.stateLabel.textColor = RBColor(179, 179, 179);
}
- (void)pullDownRefreshLoadData {
    [super pullDownRefreshLoadData];
    [self loadNewQueryMatchRowsData];
}
- (void)pullUpRefreshLoadData{
    [self loadMoreQueryMatchRowsData];
}
-(void)loadQueryRecommendMatchRowsData{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"pageNo"] = @"1";
    dict[@"pageSize"] = @"6";
    dict[@"sportId"] = self.sportId;
    MJWeakSelf
    [RBNetworkTool GET:RBQueryRecommendMatchRowsURL parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            [weakSelf.hotRecomArray removeAllObjects];
            NSArray *hotRecomArray = [RBCompeRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"records"]];
            [weakSelf.hotRecomArray addObjectsFromArray:hotRecomArray];
            [weakSelf.tableView reloadData];
        }
    } error:^(id responseObject) {
    } failure:^(NSError *error) {
    }];
}
- (void)loadNewQueryMatchRowsData{
    if (self.selectTag==4) {
        [self loadNewQueryCareMatchRowsData];
        return;
    }
    self.pageNum = 1;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"pageNo"] = @(self.pageNum);
    dict[@"pageSize"] = @(10);
    dict[@"sportId"] = self.sportId;
    dict[@"type"] = self.type;
    dict[@"searchValue"] = self.searchValue;
    dict[@"datetime"] = self.selectDateTime;
    dict[@"userId"] = [RBArchiveTool rb_userModel].userId;
    dict[@"statusType"] = @(self.selectTag);
    NSString *compIdsStr = [NSString rb_objectToJson:self.gamesIdArray];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"[" withString:@""];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"]" withString:@""];
    dict[@"compIds"] = compIdsStr;
    [self.tableView.mj_footer resetNoMoreData];
    MJWeakSelf
    [RBNetworkTool POST:RBQueryMatchRowsURL parameters:dict success:^(id responseObject){
        if ([responseObject[@"success"] boolValue]) {
            [self.dataArray removeAllObjects];
            NSArray *dataArray = [RBCompeRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"records"]];
            [self.dataArray addObjectsFromArray:dataArray];
            if (dataArray.count > 0) {
                weakSelf.loadingState = LoadingStateNormal;
            }else{
                weakSelf.loadingState = LoadingStateNoData;
            }
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_header endRefreshing];
            if (dataArray.count < 10) {
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
    } error:^(id responseObject) {
        [weakSelf.tableView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
    }];
}
- (void)loadMoreQueryMatchRowsData{
    if (self.selectTag==4) {
        [self loadMoreQueryCareMatchRowsData];
        return;
    }
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"pageNo"] = @(++self.pageNum);
    dict[@"pageSize"] = @(10);
    dict[@"sportId"] = self.sportId;
    dict[@"type"] = self.type;
    dict[@"searchValue"] = self.searchValue;
    dict[@"datetime"] = self.selectDateTime;
    dict[@"userId"] = [RBArchiveTool rb_userModel].userId;
    dict[@"statusType"] = @(self.selectTag);
    NSString *compIdsStr = [NSString rb_objectToJson:self.gamesIdArray];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"[" withString:@""];
    compIdsStr=[compIdsStr stringByReplacingOccurrencesOfString:@"]" withString:@""];
    dict[@"compIds"] = compIdsStr;
    MJWeakSelf
    [RBNetworkTool POST:RBQueryMatchRowsURL parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            NSArray *dataArray = [RBCompeRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"records"]];
            [self.dataArray addObjectsFromArray:dataArray];
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_footer endRefreshing];
            if (dataArray.count == 0) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
    } error:^(id responseObject) {
        [weakSelf.tableView.mj_footer endRefreshing];
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_footer endRefreshing];
    }];
}
-(void)loadNewQueryCareMatchRowsData{
    self.pageNum = 1;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"pageNo"] = @(self.pageNum);
    dict[@"pageSize"] = @(10);
    dict[@"sportId"] = self.sportId;
    dict[@"userId"] = [RBArchiveTool rb_userModel].userId;
    dict[@"datetime"] = self.selectDateTime;
    [self.tableView.mj_footer resetNoMoreData];
    MJWeakSelf
    [RBNetworkTool GET:RBQueryCareMatchRowsURL parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            [self.dataArray removeAllObjects];
            NSArray *dataArray = [RBCompeRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"records"]];
            [self.dataArray addObjectsFromArray:dataArray];
            for (RBCompeRecommendModel *model in self.dataArray) {
                model.followStatus=@"1";
            }
            if (dataArray.count > 0) {
                weakSelf.loadingState = LoadingStateNormal;
            }else{
                weakSelf.loadingState = LoadingStateNoData;
            }
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_header endRefreshing];
            if (dataArray.count < 10) {
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
    } error:^(id responseObject) {
        [weakSelf.tableView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
    }];
}
-(void)loadMoreQueryCareMatchRowsData{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"pageNo"] = @(++self.pageNum);
    dict[@"pageSize"] = @(10);
    dict[@"sportId"] = self.sportId;
    dict[@"userId"] = [RBArchiveTool rb_userModel].userId;
    dict[@"datetime"] = self.selectDateTime;
    MJWeakSelf
    [RBNetworkTool GET:RBQueryCareMatchRowsURL parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            NSArray *dataArray = [RBCompeRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"records"]];
            [self.dataArray addObjectsFromArray:dataArray];
            for (RBCompeRecommendModel *model in self.dataArray) {
                model.followStatus=@"1";
            }
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_footer endRefreshing];
            if (dataArray.count == 0) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
    } error:^(id responseObject) {
        [weakSelf.tableView.mj_footer endRefreshing];
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_footer endRefreshing];
    }];
}
- (void)loadAppUserCareUserFollow:(RBCompeRecommendModel *)model WithUrl:(NSString *)url WithRemindTime:(NSString *)remindTime{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"commonId"] = model.Id;
    dict[@"sportId"] = self.sportId;
    dict[@"type"] = @"3";
    dict[@"userId"] = [RBArchiveTool rb_userModel].userId;
    if ([model.followStatus intValue]==0&&remindTime.length>0) {
        NSInteger time = [[NSString rb_timeStringIntoYearMonDayTimeStamp:model.matchTime] integerValue] - [remindTime integerValue]*60;
        dict[@"remindTime"] = [NSString rb_timeStampIntoTimeString:[NSString stringWithFormat:@"%ld",time]];
    }
    MJWeakSelf
    [RBNetworkTool POST:url parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            if ([model.followStatus intValue] == 0) {
                model.followStatus = @"1";
                [RBToast rb_showTopWithText:@"已收藏" topOffset:[[RBTool rb_getCurrentController] RBStatusBarH]+10 duration:1.5 andLeftImage:@"check"];
            }else{
                model.followStatus = @"0";
                [RBToast rb_showTopWithText:@"已取消收藏" topOffset:[[RBTool rb_getCurrentController] RBStatusBarH]+10 duration:1.5 andLeftImage:@"check"];
                [weakSelf loadNewQueryCareMatchRowsData];
            }
            [weakSelf.tableView reloadData];
        }
    } error:^(id responseObject) {
    } failure:^(NSError *error) {
    }];
}
-(void)loadDictInfoData:(RBCompeRecommendModel *)model{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"code"]=@"match_defore_remind";
    MJWeakSelf
    [RBNetworkTool GET:RBDictInfoURL parameters:dict success:^(id responseObject) {
        if ([responseObject[@"success"] boolValue]) {
            [weakSelf.collTimeArray removeAllObjects];
            NSArray *collTimeArray = [RBCompeRemindModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"]];
            [weakSelf.collTimeArray addObjectsFromArray:collTimeArray];
            [weakSelf rb_showTimeSheetView:model];
        }
    } error:^(id responseObject) {
    } failure:^(NSError *error) {
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
    }
    self.tableView.mj_footer.hidden=(self.dataArray.count == 0);
    [self.tableView rb_tableViewDisplayWithMsg:@"暂无内容" blankImg:@"qsy_zwxl" necessaryForRowCount:self.dataArray.count type:3];
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        RBCompeRecomViewCell *compeRecomViewCell = [tableView dequeueReusableCellWithIdentifier:@"RBCompeRecomViewCell" forIndexPath:indexPath];
        compeRecomViewCell.hotRecomArray=self.hotRecomArray;
        return compeRecomViewCell;
    }else{
        RBBasBallGameViewCell *basBallGameViewCell = [tableView dequeueReusableCellWithIdentifier:@"RBBasBallGameViewCell" forIndexPath:indexPath];
        basBallGameViewCell.model = self.dataArray[indexPath.row];
        MJWeakSelf
        basBallGameViewCell.collectButtonTapBlock = ^(RBCompeRecommendModel * _Nonnull model) {
            if (![RBArchiveTool isLogin]) {
                [[RBOneKeyLogin shareInstance] rb_startLoginWithControllerType:RBOneKeyLoginVcTypeTopVc tabBarItemSelectIndex:0 otherSource:nil];
                return;
            }
            [weakSelf rb_showGameRemindPickerView:model];
        };
        return basBallGameViewCell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    RBCompeRecommendModel *model = self.dataArray[indexPath.row];
    RBCompeDetailListController *compeDetailListVc = [[RBCompeDetailListController alloc] init];
    compeDetailListVc.sportId = self.sportId;
    compeDetailListVc.matchId = model.Id;
    MJWeakSelf
    compeDetailListVc.collectButtonTapBlock = ^(NSString * _Nonnull iscollectStr) {
        model.followStatus = iscollectStr;
        [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    };
    [self.navigationController pushViewController:compeDetailListVc animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if(!RBArrayIsEmpty(self.hotRecomArray)){
            return RBScaleWidth(112);
        }else{
            return 0;
        }
    }else{
        return RBScaleWidth(98);
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    RBCompeSectionTitleView *compeSectionTitleView = [[RBCompeSectionTitleView alloc] init];
    compeSectionTitleView.selectCurrentTag = self.selectTag;
    compeSectionTitleView.section = section;
    compeSectionTitleView.hotRecomArray=self.hotRecomArray;
    compeSectionTitleView.titleArray = @[@"全部",@"进行中",@"未开赛",@"已完场",@"已收藏"];
    MJWeakSelf
    compeSectionTitleView.didClickSelectedItemAtIndexBlock = ^(NSInteger section, NSInteger index) {
        weakSelf.selectTag = index;
        if (weakSelf.selectTag==4) {
            if (![RBArchiveTool isLogin]) {
                [[RBOneKeyLogin shareInstance] rb_startLoginWithControllerType:RBOneKeyLoginVcTypeTopVc tabBarItemSelectIndex:2 otherSource:nil];
                return;
            }
            [weakSelf loadNewQueryMatchRowsData];
        }else{
            [weakSelf loadNewQueryMatchRowsData];
        }
    };
    return compeSectionTitleView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        if(!RBArrayIsEmpty(self.hotRecomArray)){
            return RBScaleWidth(41);
        }else{
            return 0.01;
        }
    }
    return RBScaleWidth(41);
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [[UIView alloc] initWithFrame:CGRectMake(0,0,RBScreenWidth,0.01)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)listView {
    return self.view;
}
#pragma mark - 响应事件
-(void)rb_showGameRemindPickerView:(RBCompeRecommendModel *)model{
    if ([model.followStatus intValue] == 1) {
        [self loadAppUserCareUserFollow:model WithUrl:RBUpcareUserFollowURL WithRemindTime:@""];
    }else{
        [self loadDictInfoData:model];
    }
}
-(void)rb_showTimeSheetView:(RBCompeRecommendModel *)model{
    NSMutableArray *typeArray = [NSMutableArray array];
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
    stringPickerView.pickerMode = BRStringPickerComponentSingle;
    stringPickerView.title = @"设置赛前提醒时间";
    for (RBCompeRemindModel *remindModel in self.collTimeArray) {
        [typeArray addObject:remindModel.name];
    }
    stringPickerView.dataSourceArr = typeArray;
    MJWeakSelf
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        RBCompeRemindModel *remindModel = weakSelf.collTimeArray[resultModel.index];
        NSString *valueStr = remindModel.value;
        NSInteger time = [[NSString rb_timeStringIntoTimeStamp:model.matchTime] integerValue]-[[NSString rb_timeStringIntoTimeStamp:[NSString rb_getCurrentTime]] integerValue];
        if(time < [valueStr integerValue]*60){
            [MBProgressHUD rb_showAutoMessage:@"赛前时间已经超过" ToView:RBWindow];
            return;
        }
        [weakSelf loadAppUserCareUserFollow:model WithUrl:RBCareUserFollowURL WithRemindTime:valueStr];
    };
    BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.doneTextColor = RBColor(76, 136, 255);
    customStyle.doneTextFont = RBPingFangFont(15);
    customStyle.cancelTextColor = RBColor(51, 51, 51);
    customStyle.cancelTextFont = RBPingFangFont(15);
    customStyle.titleTextFont = RBPingFangMediumFont(15);
    customStyle.titleTextColor = RBColor(51, 51, 51);
    customStyle.topCornerRadius = 10;
    customStyle.rowHeight = RBScaleWidth(48);
    customStyle.pickerHeight = RBScaleWidth(289);
    if (@available(iOS 13.0, *)) {
        customStyle.pickerColor = [UIColor whiteColor];
    } else {
        customStyle.pickerColor = [UIColor whiteColor];
    }
    customStyle.separatorColor = RBColor(204, 204, 204);
    stringPickerView.pickerStyle = customStyle;
    [stringPickerView show];
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.y = RBNAVIGATION_BAR_HEIGHT;
    self.view.height = RBScreenHeight-RBNAVIGATION_BAR_HEIGHT-RBTAB_BAR_HEIGHT;
}
-(NSMutableArray *)weekArray{
    if (_weekArray==nil) {
        _weekArray=[NSMutableArray array];
    }
    return _weekArray;
}
-(NSMutableArray *)hotRecomArray{
    if (_hotRecomArray==nil) {
        _hotRecomArray=[NSMutableArray array];
    }
    return _hotRecomArray;
}
-(NSMutableArray *)dataArray{
    if (_dataArray==nil) {
        _dataArray=[NSMutableArray array];
    }
    return _dataArray;
}
- (NSMutableArray *)collTimeArray{
    if (_collTimeArray==nil) {
        _collTimeArray = [NSMutableArray array];
    }
    return _collTimeArray;
}
- (NSMutableArray *)gamesIdArray{
    if(_gamesIdArray==nil){
        _gamesIdArray = [NSMutableArray array];
    }
    return _gamesIdArray;
}
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        if (@available(iOS 15.0, *)) {
            self.tableView.sectionHeaderTopPadding = 0;
        }
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _tableView.estimatedRowHeight = 44;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RBScreenWidth, 0.01)];
        [_tableView registerClass:[RBCompeRecomViewCell class] forCellReuseIdentifier:@"RBCompeRecomViewCell"];
        [_tableView registerClass:[RBBasBallGameViewCell class] forCellReuseIdentifier:@"RBBasBallGameViewCell"];
    }
    return _tableView;
}
@end
